package day05;

import java.util.Scanner;

/**
 * @author tongchen
 * @create 2022-11-24 23:17
 */
public class Day05_02 {
    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        //简历数组
        int[]arr=new int[n];
        //建立计数数组
        long []sum=new long[n];
        int index=0;//定义sum下标
        //输入数组
        for(int i=0;i<arr.length;++i){
            arr[i]=scan.nextInt();
        }
        //定义max
        long sums=0;
        long num=0;//定义num
        //遍历数组
        long num2=0;
        int i=0;
      while(i<arr.length){
          while(i<arr.length&&arr[i]>=0){
              num+=arr[i];
              i++;
          }
          //正数相加
          if(num>0){
              sum[index++]=num;
              num=0;
          }

          while(i< arr.length&&arr[i]<=0){
              num2+=arr[i];
          }
          //负数相加
          if(num2<0){
              sum[index++]=num2;
              num2=0;
          }
      }
       //遍历寻找最大值
        int j=0;
      int maxIndex=0;
        while(sum[j]!=0){
            if(sum[j]>sum[maxIndex]){
                maxIndex=j;
                j++;
            }
        }
        //求和

    }
}
